package com.evil.common.core.util;

import com.evil.common.core.constant.AppConstant;
import com.evil.common.core.constant.RedisConstant;

/**
 *
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public class RedisKeyUtil {

    /**
     * 登录token
     */
    public static String accessTokenKey(String token) {
        return RedisConstant.ACCESS_TOKEN_KEY_PREFIX + token;
    }

    /**
     * 用户登录token列表
     */
    public static String accessUserTokenKey(Long userId) {
        return RedisConstant.ACCESS_USER_TOKEN_PREFIX + userId;
    }

    /**
     * 企业token列表
     */
    public static String accessEnterpriseTokenKey(Long enterpriseId, Long userId) {
        return RedisConstant.ACCESS_ENTERPRISE_TOKEN_PREFIX + enterpriseId + ":" + userId;
    }

    /**
     * 会话id Key
     *
     * @param requestUuid requestUuid
     * @return String
     */
    public static String requestUuidKey(String requestUuid) {
        return RedisConstant.REQUEST_UUID_PREFIX + requestUuid;
    }

    /**
     * 当前会话是否禁止使用缓存
     *
     * @return String
     */
    public static String requestUuidClearCache() {
        String requestUuid = ServletUtils.getRequest().getHeader(AppConstant.HEADER_REQUEST_UUID);
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + RedisConstant.CANT_USE_CACHE_PREFIX;
    }
}
